import { Component, OnInit} from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { config } from '../../shared/smartadmin.config';

declare var $: any;
declare var echarts: any;
declare var Viewer: any;
@Component({
	selector: 'sa-repaired-detail-list',
	templateUrl: './repaired-detail-list.component.html',
	styleUrls: ['./repaired-detail-list.component.css']
})
export class RepairedDetailListComponent implements OnInit {
    tableData = []; //table数据
	parentCurPage: number; //父级激活页码
	parentRowId: string; //父级Id
	carDeatailUseList = carTypeListObj.carDeatailUseList
	constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
		activatedRoute.queryParams.subscribe(queryParams => {
			this.parentCurPage = queryParams.nowPage || 1;
			this.parentRowId = queryParams.id || this.parentRowId;
		});
	}

	ngOnInit() {
		this.load();
	}
	// table刷新
	refresh() {
		this.load();
	}
	// 初始化加载list数据
	load() {
		this.jsonApiService.http_obj("sanitation/deviceRepaired/sanitationDeviceRepairedHistory.html", {id:this.parentRowId}).subscribe(result => {
		    if(result.success){
                this.tableData = result.data;
                for(let item of this.tableData){
                    item.useTypeL2 = this.carDeatailUseList[item.useTypeL2] || '';
                }
            }
		})
	}
	// 返回
	goBack(){
	    this.router.navigate(['/installation-management/repaired-record'], {queryParams: {nowPage: this.parentCurPage}});
	}
	// 跳转维修详细
	repaireDetail(row){
	    this.router.navigate(['/installation-management/repaired-record/repaired-detail'],{ queryParams: { id: row.id,parentId:this.parentRowId,nowPage: this.parentCurPage}});
	}
	// 删除功能
	deleteRow(row){
		this.jsonApiService.confirm_message('此操作将永久删除数据,确认要删除?').then(()=>{
			let reqdata = 'id=' + row.id;
			this.jsonApiService.http("sanitation/deviceRepaired/deleteRepairedItemById.html", reqdata).subscribe(data => {
				this.jsonApiService.message(data.message);
				if(data.success){
					this.load();
				}
			})
		})
	}
}